package cj.web.tb.controllers;

import java.util.List;
import java.util.Map;

import net.paoding.rose.web.annotation.Param;
import net.paoding.rose.web.annotation.rest.Post;
import net.sf.json.JSONObject;

import org.springframework.beans.factory.annotation.Autowired;

import cj.web.login.controllers.BaseController;
import cj.web.tb.dao.TBNetInterfaceDAO;
import cj.web.tb.domain.TBRaterRegistration;

/**
 * 官网接口
 * @author Administrator
 *
 */
public class TBNetInterface extends BaseController {
	
	//图片位置
	private final static String IMG_PATH="http://resource.whccwh.com/resourceImg/";
	
	
	@Autowired
	private TBNetInterfaceDAO tBNetInterfaceDao;

	/**
	 * 专家列表
	 * @param type		专家类型
	 * @param start		起始
	 * @param length	结束
	 * @return
	 */
	@Post("getRaterRegList")
	public String queryRaterRegList(@Param("type") int type,@Param("start") int start,@Param("length") int length) {
		JSONObject jo = new JSONObject();
		
		List<Map> objs = tBNetInterfaceDao.queryRaterRegByType(type, start, length);
		
		int size = tBNetInterfaceDao.queryRaterRegByTypeSize(type);
		jo.put("rows", objs);
		jo.put("total", size);
		return "@"+jo.toString();
	}
	
	/**
	 * 专家详情
	 * @param id
	 * @return
	 */
	@Post("getRaterRegDetail")
	public String queryRaterRegDetail(@Param("id") int id) {
		JSONObject jo = new JSONObject();
		
		TBRaterRegistration obj = tBNetInterfaceDao.queryRaterRegById(id);
		
		if(obj!=null){
			obj.setPhoto(IMG_PATH+obj.getPhoto());
		}
		
		jo.put("obj", obj);
		return "@"+jo.toString();
	}
	
	/**
	 * 学校申报列表
	 * @param areaName
	 * @param schoolName
	 * @param start
	 * @param length
	 * @return
	 */
	@Post("querySchoolRegList")
	public String querySchoolRegList(@Param("areaName") String areaName,@Param("start") int start,@Param("length") int length) {
		JSONObject jo = new JSONObject();
		
		List<Map> objs = tBNetInterfaceDao.querySchoolReg(areaName, start, length);
		
		int size = tBNetInterfaceDao.querySchoolRegSize(areaName);
		jo.put("rows", objs);
		jo.put("total", size);
		return "@"+jo.toString();
	}
	
	/**
	 * 学校申报详情
	 * @param id
	 * @return
	 */
	@Post("getSchoolRegDetail")
	public String querySchoolRegDetail(@Param("id") int id) {
		JSONObject jo = new JSONObject();
		
		List<Map> objs = tBNetInterfaceDao.querySchoolRegItemById(id);
		
		jo.put("objs", objs);
		return "@"+jo.toString();
	}
}